<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="系统消息"></uni-navbar></view>

		<view class="search-view"><u-search class="search-input" @search="search" @custom="search"></u-search></view>
		<u-tabs class="uTabs" :list="tabsList" v-model="tabsCurrent" @change="tabsChange" :is-scroll="false"></u-tabs>

		<view class="list-box" :style="{ background: loading == 'nodata' ? 'none' : '#fff' }">
			<view class="list-info_01" v-for="(item, index) of systemList" :key="item.id" @click="navTo(item)">
				<view class="info-title">{{ item.msgTitle }}</view>
				<view class="info-btm">
					<view class="btm-left clamp">
						<text class="left-name">{{ item.receiveUserName }}</text>
						<text class="left-time">{{ item.createTime }}</text>
					</view>
					<view class="btm-right">
						<view class="right-type" :style="'color:' + colorMap[item.readStatus]">{{ item.readStatus == 2 ? '未读' : '已读' }}</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="loading" />
		</view>

		<u-back-top :scroll-top="scrollTop" top="200"></u-back-top>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			scrollTop: 0,
			tabsCurrent: 0,
			tabsList: [
				{
					name: '未读',
					value: 2
				},
				{
					name: '已读',
					value: 1
				}
			],
			colorMap: {
				0: '#0099ff',
				1: '#ff9900',
				2: '#19be6b'
			},
			readStatus: 0,
			title: '',
			systemList: [],

			message: {
				bizType: '',
				readStatus: '2',
				title: ''
			},
			loading: 'loadmore'
		};
	},
	onLoad() {
		this.loadLogin();
		this.loadData();
	},
	onShow() {
		this.loadData('refresh');
	},
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.sysUser) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
				this.roleCodes = this.userInfo.roleCodes.join(',');

				this.pageNum = 1;
				this.pageSize = 15;
			} else {
				this.$logout();
			}
		},
		//列表
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}
			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				userId: this.userId,
				clientCode: this.clientCode,
				message: this.message
			};
			this.$request('/system/sysMsgPush/list', data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.systemList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.systemList = this.systemList.concat(res.data.records);
				this.loaded = true;
				if (this.systemList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		tabsChange(index) {
			this.tabsCurrent = index;
			this.type(this.tabsList[index].value);
		},
		search(e) {
			this.message.title = e;
			this.loadData('refresh');
		},
		type(e) {
			this.readStatus = e;
			this.message.readStatus = e.toString();
			this.loadData('refresh');
		},
		navTo(item) {
			let url = '';
			this.$request('/system/sysMsgPush/query?id=' + item.id).then((res) => {
				console.log(res.data);
			});
			//建议
			if (item.msgType == '1') {
				switch (item.bizType) {
					case '1':
						url = '/pagesB/proposal/list?status=' + item.bizType;
						this.navigateTo(url);
						break;
					case '5':
						url = '/pagesB/proposal/list?status=' + item.bizType;
						this.navigateTo(url);
						break;
					case 'lm':
						url = '/pagesB/proposal/detail_lianming?id=' + item.bizKey;
						this.navigateTo(url);
						break;
					default:
						if (!item.bizKey) return false;
						url = '/pagesB/will/detail?id=' + item.bizKey;
						this.navigateTo(url);
				}
			}

			//民情直通
			if (item.msgType == '2') {
				if (!item.bizKey) return false;
				url = '/pagesB/will/detail?id=' + item.bizKey;
				this.navigateTo(url);
			}

			//我的请假
			if (item.msgType == '8') {
				switch (item.bizType) {
					case '11':
						url = '/pagesB/oa/detail_no3?id=' + item.bizKey;
						this.navigateTo(url);
						break;
					case '13':
						url = '/pagesB/oa/detail_no2?id=' + item.bizKey;
						this.navigateTo(url);
						break;
					case '14':
						url = '/pagesB/oa/detail_no5?id=' + item.bizKey;
						this.navigateTo(url);
						break;
					case '21':
						url = '/pagesB/oa/detail_no3?id=' + item.bizKey;
						this.navigateTo(url);
						break;
					case '23':
						url = '/pagesB/oa/detail_no2?id=' + item.bizKey;
						this.navigateTo(url);
						break;
					case '24':
						url = '/pagesB/oa/detail_no5?id=' + item.bizKey;
						this.navigateTo(url);
						break;
					default:
						if (!item.bizKey) return false;
						url = '/pagesB/oa/detail_no1?id=' + item.bizKey;
						this.navigateTo(url);
				}
			}

			//会议发言
			if (item.msgType == '7') {
				if (!item.bizKey) return false;
				url = '/pagesB/speech/detail?id=' + item.bizKey;
				this.navigateTo(url);
			}

			//会议活动
			if (item.msgType == '3') {
				if (!item.bizKey) return false;
				url = '/pagesB/meeting/detail?id=' + item.bizKey;
				this.navigateTo(url);
			}

			//履职
			if (item.msgType == '4') {
				switch (item.bizType) {
					case '12':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=2&flag=zxhd&name=人大活动';
						this.navigateTo(url);
						break;
					case '13':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=3&flag=hyfy&name=会议发言';
						this.navigateTo(url);
						break;
					case '14':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=4&flag=sz&name=述职';
						this.navigateTo(url);
						break;
					case '15':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=5&flag=wszl&name=文史资料';
						this.navigateTo(url);
						break;
					case '16':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=6&flag=xxpx&name=学习培训';
						this.navigateTo(url);
						break;
					case '17':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=7&flag=qthd&name=其他活动';
						this.navigateTo(url);
						break;
					case '111':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=11&flag=szxhd&name=省人大活动';
						this.navigateTo(url);
						break;
					case '112':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=12&flag=ztbg&name=专题报告';
						this.navigateTo(url);
						break;
					case '1101':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=101&flag=perform_101&name=日常联络';
						this.navigateTo(url);
						break;
					case '1102':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=102&flag=perform_102&name=实事公益';
						this.navigateTo(url);
						break;
					case '22':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=2&flag=zxhd&name=人大活动';
						this.navigateTo(url);
						break;
					case '23':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=3&flag=hyfy&name=会议发言';
						this.navigateTo(url);
						break;
					case '24':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=4&flag=sz&name=述职';
						this.navigateTo(url);
						break;
					case '25':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=5&flag=wszl&name=文史资料';
						this.navigateTo(url);
						break;
					case '26':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=6&flag=xxpx&name=学习培训';
						this.navigateTo(url);
						break;
					case '27':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=7&flag=qthd&name=其他活动';
						this.navigateTo(url);
						break;
					case '211':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=11&flag=szxhd&name=省人大活动';
						this.navigateTo(url);
						break;
					case '212':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=12&flag=ztbg&name=专题报告';
						this.navigateTo(url);
						break;
					case '2101':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=101&flag=perform_101&name=日常联络';
						this.navigateTo(url);
						break;
					case '2102':
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=102&flag=perform_102&name=实事公益';
						this.navigateTo(url);
						break;
					default:
						if (!item.bizKey) return false;
						url = '/pagesB/duties/detail?id=' + item.bizKey + '&code=1&flag=zxhy&name=人大会议';
						this.navigateTo(url);
				}
			}
		},
		navigateTo(url) {
			uni.navigateTo({
				url: url
			});
		}
	}
};
</script>

<style lang="scss">
.list-box {
	padding: 0 30rpx;
	background-color: #fff;
}
</style>
